package hutech.ksv.service;

import java.io.Serializable;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.springframework.stereotype.Service;

@Service
public class Utilities implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public Date convert3InputStringtoDate(String ngay, String thang, String nam) {
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
		StringBuilder strBuilder = new StringBuilder();
		strBuilder.append(ngay);
		strBuilder.append("/");
		strBuilder.append(thang);
		strBuilder.append("/");
		strBuilder.append(nam);	
		Date date = null;
		java.util.Date utilDate = new java.util.Date();
		try {
			utilDate = formatter.parse(strBuilder.toString());
			date = new Date(utilDate.getTime());
		} catch (ParseException e) {
			e.printStackTrace();
			System.out.println("Ham convert3InputStringtoDate bi loi");
		}		
		return date;
	}

	public Date convertUltilDateToSQLDate(java.util.Date utilDate) {
		Date date = null;
		date = new Date(utilDate.getTime());
		return date;
	}
	
	public Date convertFromStringToDate(String strDate) {
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
		Date date = null;
		java.util.Date utilDate = new java.util.Date();
		try {
			utilDate = formatter.parse(strDate);
			date = new Date(utilDate.getTime());
		} catch (ParseException e) {
			e.printStackTrace();
			System.out.println("Ham convert3InputStringtoDate bi loi");
		}		
		return date;
	}
}
